package com.pro.common.modules.service.dependencies.config.component;


import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.pro.framework.json.service.EnumJsonType;
import com.pro.framework.json.service.IJsonService;
import com.pro.framework.json.service.IJsonServiceFactory;
import com.pro.framework.json.service.JsonService;
import com.pro.framework.json.util.ObjectMapperBuilder;


public class JsonServiceFactory implements IJsonServiceFactory<EnumJsonType> {
    private final JsonService mapperCamelCase;
    private final JsonService mapperUnderLine;

    public JsonServiceFactory() {
        // shein的参数和返回结构
        this.mapperCamelCase = new JsonService(ObjectMapperBuilder.buildObjectMapper());
        this.mapperUnderLine = new JsonService(ObjectMapperBuilder.buildObjectMapper());
        this.mapperUnderLine.getObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
    }

    @Override
    public IJsonService load(EnumJsonType type) {
        return type.getIsUnderline() ? mapperUnderLine : mapperCamelCase;
    }

    public IJsonService getService(Boolean isUnderline) {
        return isUnderline ? mapperUnderLine : mapperCamelCase;
    }
}
